package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.RegionInfo;
import com.example.mountainwalker.service.RegionService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/regions")
public class RegionController {

    private final RegionService regionService;

    public RegionController(RegionService regionService) {
        this.regionService = regionService;
    }

    @GetMapping
    public List<RegionInfo> getAllRegions() {
        return regionService.getAllRegions();
    }

    @GetMapping("/{regionId}")
    public RegionInfo getRegionById(@PathVariable Integer regionId) {
        return regionService.getRegionById(regionId);
    }

    @PostMapping
    public int addRegion(@RequestBody RegionInfo regionInfo) {
        return regionService.insertRegion(regionInfo);
    }

    @PutMapping
    public int updateRegion(@RequestBody RegionInfo regionInfo) {
        return regionService.updateRegion(regionInfo);
    }

    @DeleteMapping("/{regionId}")
    public int deleteRegion(@PathVariable Integer regionId) {
        return regionService.deleteRegion(regionId);
    }

    @GetMapping("/search/province")
    public List<RegionInfo> searchByProvince(@RequestParam(required = false) String province) {
        return regionService.searchByProvince(province);
    }

    @GetMapping("/search/city")
    public List<RegionInfo> searchByCity(@RequestParam(required = false) String city) {
        return regionService.searchByCity(city);
    }
}